package com.fjwt.gz.mgr.mq;

import com.fjwt.gz.components.mq.model.ExportExcelMQ;
import com.fjwt.gz.core.constants.Constants;
import com.fjwt.gz.core.utils.SpringBeansUtil;
import com.fjwt.gz.db.entity.SysExportTaskEntity;
import com.fjwt.gz.service.activity.AbstractExportReport;
import com.fjwt.gz.service.impl.SysExportTaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 接收MQ消息
 * 业务： 导出活动报表
 *
 */
@Slf4j
@Component
public class ExportExcelMQReceiver implements ExportExcelMQ.IMQReceiver {

    @Autowired
    private SysExportTaskService sysExportTaskService;

    @Override
    public void receive(ExportExcelMQ.MsgPayload payload) {
//        SysExportTaskEntity sysExportTaskEntity = sysExportTaskService.getById(payload.getExportTaskId());
//        log.info("开始处理导出报表任务：{}", sysExportTaskEntity);
//        if (ObjectUtils.isNotEmpty(sysExportTaskEntity)) {
//            sysExportTaskEntity.setStartTime(new Date());
//            sysExportTaskEntity.setStatus(Constants.EXPORT_TASK_ENUM.STATUS.FAILED);
//
//            AbstractExportReport exportExcelService = SpringBeansUtil.getBean(sysExportTaskEntity.getRequestCode() + "ExportReport", AbstractExportReport.class);
//            if (ObjectUtils.isEmpty(exportExcelService)) {
//                sysExportTaskEntity.setErrorMsg("该类活动暂无报表导出");
//            }else {
//                try {
//                    String ossUrl = exportExcelService.exportActivityExcel(sysExportTaskEntity);
//                    sysExportTaskEntity.setDownloadUrl(ossUrl);
//                    sysExportTaskEntity.setStatus(Constants.EXPORT_TASK_ENUM.STATUS.SUCCESS);
//                }catch (Exception e) {
//                    sysExportTaskEntity.setErrorMsg(e.getMessage());
//                }
//            }
//            sysExportTaskEntity.setCompletedTime(new Date());
//            sysExportTaskService.updateById(sysExportTaskEntity);
//        }
    }

}
